package com.example.enterprisemanager.mvvm.fragment.manager;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import com.example.enterprisemanager.BR;
import com.example.enterprisemanager.R;
import com.example.enterprisemanager.base.BaseMainFragment;
import com.example.enterprisemanager.databinding.FragmentManagerBinding;

/**
 * A simple {@link Fragment} subclass.
 */
public class ManagerFragment extends BaseMainFragment<FragmentManagerBinding, ManagerViewModel> {


    public static ManagerFragment newInstance() {
        return new ManagerFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_manager;
    }

    @Override
    protected Class<ManagerViewModel> getModelClass() {
        return ManagerViewModel.class;
    }


    @Override
    protected int getVariableId() {
        return BR.viewModel;
    }

    @Override
    protected void initView() {
        super.initView();
        mBinding.toolbar.setTitle(R.string.manager);
        initToolbarNav(mBinding.toolbar, true);
    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {
        mViewModel.startFrag.observe(this, (data) -> {
            if (data == null)
                return;
            if (data == 0) {
                start(WaitPurchaseFragment.newInstance());
            } else if (data == 1) {
                start(EnrollFragment.newInstance());
            } else if (data == 2) {
                start(RuinFragment.newInstance());
            }
        });
    }


    /**
     * 类似于 Activity的 onNewIntent()
     */
    @Override
    public void onNewBundle(Bundle args) {
        super.onNewBundle(args);

        Toast.makeText(_mActivity, args.getString("from"), Toast.LENGTH_SHORT).show();
    }

}
